package com.yjtc.cbg.commonutildemo.Util;

import android.content.Context;
import android.widget.Toast;

import com.yjtc.cbg.commonutildemo.data.httpService;
import com.yjtc.cbg.commonutildemo.entity.Student;

import retrofit.Call;
import retrofit.Callback;
import retrofit.GsonConverterFactory;
import retrofit.Response;
import retrofit.Retrofit;

/**
 * Created by chenboge on 2016/11/28.
 */
public class HttpUtil {

    private Context mContext;

    private httpService mService = null;

    public HttpUtil(Context context) {
        this.mContext = context;
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://localhost:8080")
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        mService = retrofit.create(httpService.class);
    }

    public void getdata() {
        Call<Student> call = mService.loadRepo();
        call.enqueue(new Callback<Student>() {
            @Override
            public void onResponse(Response<Student> response) {
                Toast.makeText(mContext, response.body().getName(), Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onFailure(Throwable t) {
                Toast.makeText(mContext, "error", Toast.LENGTH_SHORT).show();
            }
        });
    }

}
